package demo;

import com.sun.org.apache.xpath.internal.SourceTree;
import org.junit.Test;

import java.util.Comparator;
import java.util.function.Consumer;

/**
 * @Author: WWQ
 * @Date: 2019/4/3 14:31
 * @Version 1.0
 */
public class LambdaTest2 {
    /**
     *无参数，无返回值
     */
    @Test
    public void test1(){

        Runnable runnable =new Runnable(){
            @Override
            public void run() {
                System.out.println("hello word");
            }
        };
        runnable.run();
        System.out.println("--------------------------------------------------");

        Runnable runnable12=()-> System.out.println("htllo Lambda");
        runnable12.run();

    }

    @Test
    public void test2(){
    Consumer<String> consumer=(x)-> System.out.println(x);
    consumer.accept("111");
    }

    @Test
    public void test3(){
        Comparator<Integer> comparator=(x,y)->{
            System.out.println("函数式编程");
            return Integer.compare(20,30);
        };

    }
    @Test
    public void test4(){
        Comparator<Integer> comparator=(x,y)->Integer.compare(20,30);
        System.out.println(comparator);
    }

    @Test
    public void test5(){

        System.out.println(getValue(100,(x)->x*x));


    }

    public Integer getValue(Integer x,MyFunction myFunction){
        return myFunction.test(x);
    }
}
